﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using SHDocVw;
using System.Threading;

namespace ScoreHelper
{
    public class IEPrintSettings
    {
        private static IEPrintSettings _inst;
        private RegistryKey HKCU_PageSetup = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup\\", true);
        private string[] _keys = new string[6] { "footer", "header", "margin_left", "margin_top", "margin_right", "margin_bottom" };
        private string[] _default = new string[6];
        private string[] _values = new string[6];
        IEPrintSettings()
        {
            for (int i = 0; i < _keys.Length; i++)
            {
                _values[i] = _default[i] = HKCU_PageSetup.GetValue(_keys[i]).ToString();
            }
        }
        public static IEPrintSettings Instance
        {
            get
            {
                if (_inst == null)
                    _inst = new IEPrintSettings();
                return _inst;
            }
        }

        public string Footer
        {
            get { return _values[0]; }
            set { _values[0] = value; }
        }

        public string Header
        {
            get { return _values[1]; }
            set { _values[1] = value; }
        }

        public string MarginLeft
        {
            get { return _values[2]; }
            set { _values[2] = value; }
        }

        public string MarginTop
        {
            get { return _values[3]; }
            set { _values[3] = value; }
        }

        public string MarginRight
        {
            get { return _values[4]; }
            set { _values[4] = value; }
        }

        public string MarginBottom
        {
            get { return _values[5]; }
            set { _values[5] = value; }
        }


        public void SaveSettings()
        {
            for (int i = 0; i < _keys.Length; i++)
            {
                HKCU_PageSetup.SetValue(_keys[i], _values[i]);
            }
        }

        public void Reset2Default()
        {
            for (int i = 0; i < _keys.Length; i++)
            {
                HKCU_PageSetup.SetValue(_keys[i], _default[i]);
            }
        }
    }
}
